class Solution {
public:
    int tribonacci(int n) {
        int a = 0, b = 1, c = 1, d = a + b + c;
        if (n == 1 || n == 2) return 1;
        if (n == 0) return 0;
        int num = n - 4;
        while ((num--) >= 0)
        {
            a = b;
            b = c;
            c = d;
            d = a + b + c;
        }
        return d;
    }
};